﻿/*
 * File: PauseScene.cs
 * Author: Gourav Das
 * Created: April 30 2011
 * Copyright: Gourav Das, 2011
 */

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using _22yards._2D;
using _22yards.Core;
using _22yards.Scenes;

namespace _22yards.Scenes.Helpers
{
    /// <summary>
    /// The pause menu comes up over the top of the game,
    /// giving the player options to resume or quit or save.
    /// </summary>
    class PauseScene : BaseMenuScene
    {

        /// <summary>
        /// Constructor.
        /// </summary>
        public PauseScene()
            : base("Paused")
        {
            // Create our menu entries.
            MenuItem resumeGameMenuItem = new MenuItem("Resume Game",0);
            MenuItem quitGameMenuItem = new MenuItem("Quit Game",1);
            MenuItem saveGameMenuItem = new MenuItem("Save Game",2);

            // Hook up menu event handlers.
            resumeGameMenuItem.Selected += OnCancel;
            quitGameMenuItem.Selected += QuitGameMenuItem_Selected;

            // Add entries to the menu.
            MenuItems.Add(resumeGameMenuItem);
            MenuItems.Add(quitGameMenuItem);
            MenuItems.Add(saveGameMenuItem);
        }


        /// <summary>
        /// Event handler for when the Quit Game menu entry is selected.
        /// </summary>
        void QuitGameMenuItem_Selected(object sender, PlayerIndexEventArgs e)
        {
            const string message = "Are you sure you want to quit at this stage?";

            MsgBoxScreen confirmQuitMsgBox = new MsgBoxScreen(message);
            confirmQuitMsgBox.Accepted += ConfirmQuitMessageBoxAccepted;

            sceneEngine.AddScene(confirmQuitMsgBox, ControllingPlayer);
        }


        /// <summary>
        /// Event handler for when the user selects ok on the "are you sure
        /// you want to quit" message box. This uses the loading screen to
        /// transition from the game back to the main menu screen.
        /// </summary>
        void ConfirmQuitMessageBoxAccepted(object sender, PlayerIndexEventArgs e)
        {
            ExitScene();
            LoadingScene.Load(sceneEngine, false, null, new BackgroundScene(), new MainMenuScene());
        }

    }
}
